<?xml version="1.0" encoding="UTF-8"?>
<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/">
  <dxl:Comment><![CDATA[
Objective: The preprocess that rewrites a nested query from IN subquery to EXIST subquery with a predicate, if
  * Query is nested with an outer IN clause
  * Inner subquery is a SELECT FROM query and
  * Projection list from inner clause refers to outer query table columns and
  * Projection list from inner clause does not refer to any inner query table columns

It should not happen if inner sub query returns set,
because a single value and a set can't be compared with "=" operator.

SELECT a IN (SELECT generate_series(1,a)) AS x FROM (SELECT generate_series(1, 3) AS a) AS s;
              QUERY PLAN
---------------------------------------
Result
->  Result
      ->  Result
SubPlan 1
  ->  Result
        ->  Result
              ->  Result
Optimizer: Pivotal Optimizer (GPORCA)
(8 rows)
]]></dxl:Comment>
  <dxl:Thread Id="0">
    <dxl:OptimizerConfig>
      <dxl:EnumeratorConfig Id="0" PlanSamples="0" CostThreshold="0"/>
      <dxl:StatisticsConfig DampingFactorFilter="0.750000" DampingFactorJoin="0.000000" DampingFactorGroupBy="0.750000" MaxStatsBuckets="100"/>
      <dxl:CTEConfig CTEInliningCutoff="0"/>
      <dxl:WindowOids RowNumber="3100" Rank="3101"/>
      <dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3">
        <dxl:CostParams>
          <dxl:CostParam Name="NLJFactor" Value="1024.000000" LowerBound="1023.500000" UpperBound="1024.500000"/>
        </dxl:CostParams>
      </dxl:CostModelConfig>
      <dxl:Hint JoinArityForAssociativityCommutativity="18" ArrayExpansionThreshold="100" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="100000" EnforceConstraintsOnDML="false" PushGroupByBelowSetopThreshold="10" XformBindThreshold="0" SkewFactor="0"/>
      <dxl:TraceFlags Value="101013,102074,102120,102146,102155,102156,103001,103003,103014,103022,103027,103029,103038,103041,104002,104003,104004,104005,106000"/>
    </dxl:OptimizerConfig>
    <dxl:Metadata SystemIds="0.GPDB">
      <dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="1" PassByValue="true">
        <dxl:DistrOpfamily Mdid="0.2222.1.0"/>
        <dxl:LegacyDistrOpfamily Mdid="0.7124.1.0"/>
        <dxl:EqualityOp Mdid="0.91.1.0"/>
        <dxl:InequalityOp Mdid="0.85.1.0"/>
        <dxl:LessThanOp Mdid="0.58.1.0"/>
        <dxl:LessThanEqualsOp Mdid="0.1694.1.0"/>
        <dxl:GreaterThanOp Mdid="0.59.1.0"/>
        <dxl:GreaterThanEqualsOp Mdid="0.1695.1.0"/>
        <dxl:ComparisonOp Mdid="0.1693.1.0"/>
        <dxl:ArrayType Mdid="0.1000.1.0"/>
        <dxl:MinAgg Mdid="0.0.0.0"/>
        <dxl:MaxAgg Mdid="0.0.0.0"/>
        <dxl:AvgAgg Mdid="0.0.0.0"/>
        <dxl:SumAgg Mdid="0.0.0.0"/>
        <dxl:CountAgg Mdid="0.2147.1.0"/>
      </dxl:Type>
      <dxl:Type Mdid="0.20.1.0" Name="Int8" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="8" PassByValue="true">
        <dxl:DistrOpfamily Mdid="0.1977.1.0"/>
        <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/>
        <dxl:EqualityOp Mdid="0.410.1.0"/>
        <dxl:InequalityOp Mdid="0.411.1.0"/>
        <dxl:LessThanOp Mdid="0.412.1.0"/>
        <dxl:LessThanEqualsOp Mdid="0.414.1.0"/>
        <dxl:GreaterThanOp Mdid="0.413.1.0"/>
        <dxl:GreaterThanEqualsOp Mdid="0.415.1.0"/>
        <dxl:ComparisonOp Mdid="0.351.1.0"/>
        <dxl:ArrayType Mdid="0.1016.1.0"/>
        <dxl:MinAgg Mdid="0.2131.1.0"/>
        <dxl:MaxAgg Mdid="0.2115.1.0"/>
        <dxl:AvgAgg Mdid="0.2100.1.0"/>
        <dxl:SumAgg Mdid="0.2107.1.0"/>
        <dxl:CountAgg Mdid="0.2147.1.0"/>
      </dxl:Type>
      <dxl:Type Mdid="0.23.1.0" Name="int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true">
        <dxl:DistrOpfamily Mdid="0.1977.1.0"/>
        <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/>
        <dxl:EqualityOp Mdid="0.96.1.0"/>
        <dxl:InequalityOp Mdid="0.518.1.0"/>
        <dxl:LessThanOp Mdid="0.97.1.0"/>
        <dxl:LessThanEqualsOp Mdid="0.523.1.0"/>
        <dxl:GreaterThanOp Mdid="0.521.1.0"/>
        <dxl:GreaterThanEqualsOp Mdid="0.525.1.0"/>
        <dxl:ComparisonOp Mdid="0.351.1.0"/>
        <dxl:ArrayType Mdid="0.1007.1.0"/>
        <dxl:MinAgg Mdid="0.2132.1.0"/>
        <dxl:MaxAgg Mdid="0.2116.1.0"/>
        <dxl:AvgAgg Mdid="0.2101.1.0"/>
        <dxl:SumAgg Mdid="0.2108.1.0"/>
        <dxl:CountAgg Mdid="0.2147.1.0"/>
      </dxl:Type>
      <dxl:GPDBScalarOp Mdid="0.410.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true" IsNDVPreserving="false">
        <dxl:LeftType Mdid="0.20.1.0"/>
        <dxl:RightType Mdid="0.20.1.0"/>
        <dxl:ResultType Mdid="0.16.1.0"/>
        <dxl:OpFunc Mdid="0.467.1.0"/>
        <dxl:Commutator Mdid="0.410.1.0"/>
        <dxl:InverseOp Mdid="0.411.1.0"/>
        <dxl:HashOpfamily Mdid="0.1977.1.0"/>
        <dxl:LegacyHashOpfamily Mdid="0.7100.1.0"/>
        <dxl:Opfamilies>
          <dxl:Opfamily Mdid="0.1976.1.0"/>
          <dxl:Opfamily Mdid="0.1977.1.0"/>
          <dxl:Opfamily Mdid="0.7028.1.0"/>
          <dxl:Opfamily Mdid="0.7100.1.0"/>
        </dxl:Opfamilies>
      </dxl:GPDBScalarOp>
      <dxl:GPDBScalarOp Mdid="0.413.1.0" Name="&gt;" ComparisonType="GT" ReturnsNullOnNullInput="true" IsNDVPreserving="false">
        <dxl:LeftType Mdid="0.20.1.0"/>
        <dxl:RightType Mdid="0.20.1.0"/>
        <dxl:ResultType Mdid="0.16.1.0"/>
        <dxl:OpFunc Mdid="0.470.1.0"/>
        <dxl:Commutator Mdid="0.412.1.0"/>
        <dxl:InverseOp Mdid="0.414.1.0"/>
        <dxl:Opfamilies>
          <dxl:Opfamily Mdid="0.1976.1.0"/>
          <dxl:Opfamily Mdid="0.7028.1.0"/>
        </dxl:Opfamilies>
      </dxl:GPDBScalarOp>
      <dxl:GPDBFunc Mdid="0.1067.1.0" Name="generate_series" ReturnsSet="true" Stability="Immutable" DataAccess="ReadsSQLData" IsStrict="true" IsNDVPreserving="false" IsAllowedForPS="false">
        <dxl:ResultType Mdid="0.23.1.0"/>
      </dxl:GPDBFunc>
      <dxl:GPDBAgg Mdid="0.2108.1.0" Name="sum" IsSplittable="true" HashAggCapable="true">
        <dxl:ResultType Mdid="0.20.1.0"/>
        <dxl:IntermediateResultType Mdid="0.20.1.0"/>
      </dxl:GPDBAgg>
      <dxl:GPDBFunc Mdid="0.65.1.0" Name="int4eq" ReturnsSet="false" Stability="Immutable" DataAccess="NoSQL" IsStrict="true" IsNDVPreserving="false" IsAllowedForPS="false">
        <dxl:ResultType Mdid="0.16.1.0"/>
      </dxl:GPDBFunc>
      <dxl:GPDBScalarOp Mdid="0.96.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true" IsNDVPreserving="false">
        <dxl:LeftType Mdid="0.23.1.0"/>
        <dxl:RightType Mdid="0.23.1.0"/>
        <dxl:ResultType Mdid="0.16.1.0"/>
        <dxl:OpFunc Mdid="0.65.1.0"/>
        <dxl:Commutator Mdid="0.96.1.0"/>
        <dxl:InverseOp Mdid="0.518.1.0"/>
        <dxl:HashOpfamily Mdid="0.1977.1.0"/>
        <dxl:LegacyHashOpfamily Mdid="0.7100.1.0"/>
        <dxl:Opfamilies>
          <dxl:Opfamily Mdid="0.1976.1.0"/>
          <dxl:Opfamily Mdid="0.1977.1.0"/>
          <dxl:Opfamily Mdid="0.7027.1.0"/>
          <dxl:Opfamily Mdid="0.7100.1.0"/>
        </dxl:Opfamilies>
      </dxl:GPDBScalarOp>
      <dxl:GPDBAgg Mdid="0.2147.1.0" Name="count" IsSplittable="true" HashAggCapable="true">
        <dxl:ResultType Mdid="0.20.1.0"/>
        <dxl:IntermediateResultType Mdid="0.20.1.0"/>
      </dxl:GPDBAgg>
      <dxl:GPDBAgg Mdid="0.2803.1.0" Name="count" IsSplittable="true" HashAggCapable="true">
        <dxl:ResultType Mdid="0.20.1.0"/>
        <dxl:IntermediateResultType Mdid="0.20.1.0"/>
      </dxl:GPDBAgg>
    </dxl:Metadata>
    <dxl:Query>
      <dxl:OutputColumns>
        <dxl:Ident ColId="5" ColName="x" TypeMdid="0.16.1.0"/>
      </dxl:OutputColumns>
      <dxl:CTEList/>
      <dxl:LogicalProject>
        <dxl:ProjList>
          <dxl:ProjElem ColId="5" Alias="x">
            <dxl:SubqueryAny OperatorName="=" OperatorMdid="0.96.1.0" ColId="4">
              <dxl:Ident ColId="2" ColName="a" TypeMdid="0.23.1.0"/>
              <dxl:LogicalProject>
                <dxl:ProjList>
                  <dxl:ProjElem ColId="4" Alias="generate_series">
                    <dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0" FuncVariadic="false">
                      <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
                      <dxl:Ident ColId="2" ColName="a" TypeMdid="0.23.1.0"/>
                    </dxl:FuncExpr>
                  </dxl:ProjElem>
                </dxl:ProjList>
                <dxl:LogicalConstTable>
                  <dxl:Columns>
                    <dxl:Column ColId="3" Attno="1" ColName="" TypeMdid="0.16.1.0"/>
                  </dxl:Columns>
                  <dxl:ConstTuple>
                    <dxl:Datum TypeMdid="0.16.1.0" Value="true"/>
                  </dxl:ConstTuple>
                </dxl:LogicalConstTable>
              </dxl:LogicalProject>
            </dxl:SubqueryAny>
          </dxl:ProjElem>
        </dxl:ProjList>
        <dxl:LogicalProject>
          <dxl:ProjList>
            <dxl:ProjElem ColId="2" Alias="a">
              <dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0" FuncVariadic="false">
                <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
                <dxl:ConstValue TypeMdid="0.23.1.0" Value="3"/>
              </dxl:FuncExpr>
            </dxl:ProjElem>
          </dxl:ProjList>
          <dxl:LogicalConstTable>
            <dxl:Columns>
              <dxl:Column ColId="1" Attno="1" ColName="" TypeMdid="0.16.1.0"/>
            </dxl:Columns>
            <dxl:ConstTuple>
              <dxl:Datum TypeMdid="0.16.1.0" Value="true"/>
            </dxl:ConstTuple>
          </dxl:LogicalConstTable>
        </dxl:LogicalProject>
      </dxl:LogicalProject>
    </dxl:Query>
    <dxl:Plan Id="0" SpaceSize="66">
      <dxl:Result>
        <dxl:Properties>
          <dxl:Cost StartupCost="0" TotalCost="441357.573926" Rows="1.000000" Width="1"/>
        </dxl:Properties>
        <dxl:ProjList>
          <dxl:ProjElem ColId="4" Alias="x">
            <dxl:SubPlan TypeMdid="0.16.1.0" SubPlanType="AnySubPlan">
              <dxl:TestExpr>
                <dxl:Comparison ComparisonOperator="=" OperatorMdid="0.96.1.0">
                  <dxl:Ident ColId="1" ColName="a" TypeMdid="0.23.1.0"/>
                  <dxl:Ident ColId="3" ColName="generate_series" TypeMdid="0.23.1.0"/>
                </dxl:Comparison>
              </dxl:TestExpr>
              <dxl:ParamList>
                <dxl:Param ColId="1" ColName="a" TypeMdid="0.23.1.0"/>
              </dxl:ParamList>
              <dxl:Result>
                <dxl:Properties>
                  <dxl:Cost StartupCost="0" TotalCost="0.000106" Rows="1.000000" Width="5"/>
                </dxl:Properties>
                <dxl:ProjList>
                  <dxl:ProjElem ColId="3" Alias="generate_series">
                    <dxl:Ident ColId="3" ColName="generate_series" TypeMdid="0.23.1.0"/>
                  </dxl:ProjElem>
                </dxl:ProjList>
                <dxl:Filter/>
                <dxl:OneTimeFilter/>
                <dxl:Result>
                  <dxl:Properties>
                    <dxl:Cost StartupCost="0" TotalCost="0.000106" Rows="1.000000" Width="5"/>
                  </dxl:Properties>
                  <dxl:ProjList>
                    <dxl:ProjElem ColId="9" Alias="ColRef_0009">
                      <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/>
                    </dxl:ProjElem>
                    <dxl:ProjElem ColId="3" Alias="generate_series">
                      <dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0" FuncVariadic="false">
                        <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
                        <dxl:Ident ColId="1" ColName="a" TypeMdid="0.23.1.0"/>
                      </dxl:FuncExpr>
                    </dxl:ProjElem>
                  </dxl:ProjList>
                  <dxl:Filter/>
                  <dxl:OneTimeFilter/>
                  <dxl:Result>
                    <dxl:Properties>
                      <dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/>
                    </dxl:Properties>
                    <dxl:ProjList>
                      <dxl:ProjElem ColId="2" Alias="">
                        <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/>
                      </dxl:ProjElem>
                    </dxl:ProjList>
                    <dxl:Filter/>
                    <dxl:OneTimeFilter/>
                  </dxl:Result>
                </dxl:Result>
              </dxl:Result>
            </dxl:SubPlan>
          </dxl:ProjElem>
        </dxl:ProjList>
        <dxl:Filter/>
        <dxl:OneTimeFilter/>
        <dxl:Result>
          <dxl:Properties>
            <dxl:Cost StartupCost="0" TotalCost="0.000105" Rows="1.000000" Width="4"/>
          </dxl:Properties>
          <dxl:ProjList>
            <dxl:ProjElem ColId="1" Alias="a">
              <dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0" FuncVariadic="false">
                <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
                <dxl:ConstValue TypeMdid="0.23.1.0" Value="3"/>
              </dxl:FuncExpr>
            </dxl:ProjElem>
          </dxl:ProjList>
          <dxl:Filter/>
          <dxl:OneTimeFilter/>
          <dxl:Result>
            <dxl:Properties>
              <dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/>
            </dxl:Properties>
            <dxl:ProjList>
              <dxl:ProjElem ColId="0" Alias="">
                <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/>
              </dxl:ProjElem>
            </dxl:ProjList>
            <dxl:Filter/>
            <dxl:OneTimeFilter/>
          </dxl:Result>
        </dxl:Result>
      </dxl:Result>
    </dxl:Plan>
  </dxl:Thread>
</dxl:DXLMessage>
